package com.wty.cmims.controller;

import com.aliyun.oss.ClientException;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.OSSException;
import com.aliyun.oss.common.auth.CredentialsProvider;
import com.aliyun.oss.common.auth.DefaultCredentialProvider;
import com.wty.cmims.service.ImageUploadService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.io.InputStream;

@RestController
@Tag(name = "文件上传接口", description = "文件上传api接口")
public class ImageUploadController {
    @Resource
    private ImageUploadService imageUploadService;
    @PostMapping("/upload")
    public String fileUpload(@RequestParam("file") MultipartFile multipartFile){
        String originalFilename = multipartFile.getOriginalFilename();
        InputStream in = null;
        try {
            in = multipartFile.getInputStream();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return imageUploadService.upload(in, originalFilename);
    }
}
